//优先级队列 加 set去重
class Solution {
public:
    struct greater
    {
        public:
        bool operator()(int a,int b)
        {
            return a>b;
        }
    };
    int thirdMax(vector<int>& nums) {
        priority_queue<int,vector<int>,greater> q;
        unordered_set<int> seen;
        for(auto& e:nums)
        {
             if (seen.find(e) == seen.end()) {
                seen.insert(e);

                 if(q.size()<3)
            q.push(e);
            else
            {
                if(e>q.top())
                {
                    q.pop();
                    q.push(e);
                }
            }
           }
        }
        if(q.size()==1)
        {
            return q.top();
        }
        else if(q.size()==2)
        {
            q.pop();
            return q.top();
        }
        else
        return q.top();
    }
};

//用3个数
class Solution {
public:
    int thirdMax(vector<int>& nums) {
        long a = LONG_MIN, b = LONG_MIN, c = LONG_MIN;
        for (auto& e : nums) {
            if (e > a) {
                c = b;
                b = a;
                a = e;
            } else if (a > e && e > b) {
                c = b;
                b = e;
            } else if (b > e && e > c) {
                c = e;
            }
        }
        return c == LONG_MIN ? a : c;
    }
};